//
//  ZHLineCollectionViewCell.m
//  Doctor
//
//  Created by liuzhishan on 15/12/16.
//  Copyright © 2015年 shanshan. All rights reserved.
//

#import "ZHLineCollectionViewCell.h"
#import "ZHDrawLineView.h"
#import "ZHClinicAllData.h"
#import "DataTool.h"
#define CIRCLERADIUS   10.5
@interface ZHLineCollectionViewCell ()

@property (nonatomic,retain) UILabel *lableDate;
@property (nonatomic,retain) UILabel *lableLastDate;
@property (nonatomic,retain) ZHDrawLineView *drawView;

@property (nonatomic,retain) ZHClinicAllData *leftModel;

@property (nonatomic,retain) ZHClinicAllData *rightModel;


@property (nonatomic,assign) NSInteger index;

@property (nonatomic,retain) NSMutableArray *dataArray;

@end

@implementation ZHLineCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        
        [self addMYCollectionChildViews];
    }
    
    
    return self;
}

-(void)addMYCollectionChildViews
{
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    
    
    UIImageView *bgImageView = [[UIImageView alloc]init];
    [bgImageView setMyFramewithX:0 andY:0 andWidth:78 andHeight:250];
    bgImageView.image = [UIImage imageNamed:@"clinic-form"];
    [self.contentView addSubview:bgImageView];
    
    
    self.lableDate = [[UILabel alloc]init];
    [self.lableDate setMyFramewithX:0 andY:250 andWidth:78 andHeight:20];
    self.lableDate.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.lableDate];
    self.lableDate.textColor = [UIColor whiteColor];
    self.lableDate.font = [UIFont systemFontOfSize:13 * WIDPro -2];
    
    self.drawView = [[ZHDrawLineView alloc]initWithFrame:bgImageView.bounds];
    self.drawView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.drawView];
    
    
    
    self.circleLeftImage = [[UIImageView alloc]init];
    self.circleLeftImage.tag = 10001;
    [self.circleLeftImage setMyFramewithX:0  andY:0 andWidth:CIRCLERADIUS andHeight:CIRCLERADIUS * 2];
    self.circleLeftImage.image = [UIImage imageNamed:@"blueCircleLeftImage"];
    [self.contentView addSubview:self.circleLeftImage];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clinic:)];
    [self.circleLeftImage addGestureRecognizer:tap];
    self.circleLeftImage.userInteractionEnabled = YES;
    
    
    self.circleRightImage = [[UIImageView alloc]init];
    self.circleRightImage.tag = 10002;
    [self.circleRightImage setMyFramewithX:78-CIRCLERADIUS andY:0 andWidth:CIRCLERADIUS andHeight:CIRCLERADIUS*2];
    self.circleRightImage.image = [UIImage imageNamed:@"blueCircleRightImage"];
     [self.contentView addSubview:self.circleRightImage];
    
    tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clinic:)];
    [self.circleRightImage addGestureRecognizer:tap];
    self.circleRightImage.userInteractionEnabled = YES;
    
    
    
    self.circleLeftOrangeImage = [[UIImageView alloc]init];
    self.circleLeftOrangeImage.tag = 10003;
    [self.circleLeftOrangeImage setMyFramewithX:0 andY:0 andWidth:CIRCLERADIUS andHeight:CIRCLERADIUS * 2];
    self.circleLeftOrangeImage.image = [UIImage imageNamed:@"orangeCircleLeftImage"];
    [self.contentView addSubview:self.circleLeftOrangeImage];
    
    
    tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clinic:)];
    [self.circleLeftOrangeImage addGestureRecognizer:tap];
    self.circleLeftOrangeImage.userInteractionEnabled = YES;
    
   
    
    self.circleRightOrangeImage = [[UIImageView alloc]init];
    self.circleRightOrangeImage.tag = 10004;
    [self.circleRightOrangeImage setMyFramewithX:78-CIRCLERADIUS andY:0 andWidth:CIRCLERADIUS andHeight:CIRCLERADIUS * 2];
    self.circleRightOrangeImage.image = [UIImage imageNamed:@"orangeCircleRightImage"];
    [self.contentView addSubview:self.circleRightOrangeImage];
    
    
    tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clinic:)];
    [self.circleRightOrangeImage addGestureRecognizer:tap];
    self.circleRightOrangeImage.userInteractionEnabled = YES;
    

    
}

-(void)clinic:(UITapGestureRecognizer *)tap
{

    
    NSString *megStr = @"";
    NSString *colorName = @"blue";
    
   ZHSaveCommenMeg *meg = [ZHSaveClickDate shareData].judgeModel;
    
    
    if ([meg.judgeName isEqualToString:@"income"]) {
    
        if (tap.view == self.circleLeftImage) {
            
            NSInteger current = self.leftModel.topPrice;
            megStr = [NSString stringWithFormat:@"当日客单价:%ld",current];
            
        }
        
        else if (tap.view == self.circleRightImage)
        {
            NSInteger current = self.rightModel.topPrice;
            megStr = [NSString stringWithFormat:@"当日客单价:%ld",current];
            
        }
        
        else if (tap.view == self.circleLeftOrangeImage)
        {
            colorName = @"orange";
            NSInteger current = self.leftModel.money;
            megStr = [NSString stringWithFormat:@"当日诊所收费:%ld",current];

        }
        
        else if(tap.view == self.circleRightOrangeImage)
        {

            colorName = @"orange";
            NSInteger current = self.rightModel.money;
            megStr = [NSString stringWithFormat:@"当日诊所收费:%ld",current];

        }

        
        
    }
    
    else
    {
        
        
        if (tap.view == self.circleLeftImage) {
            
            NSInteger current = self.leftModel.firstVisit;
            megStr = [NSString stringWithFormat:@"初诊人数:%ld",current];
            
        }
        
        else if (tap.view == self.circleRightImage)
        {
            NSInteger current = self.rightModel.firstVisit;
            megStr = [NSString stringWithFormat:@"初诊人数:%ld",current];
            
        }
        
        else if (tap.view == self.circleLeftOrangeImage)
        {
            
            colorName = @"orange";
            
            NSInteger current = self.leftModel.topPrice;
            megStr = [NSString stringWithFormat:@"复诊人数:%ld",current];
            
        }
        
        else if(tap.view == self.circleRightOrangeImage)
        {
            
            colorName = @"orange";
            
            NSInteger current = self.rightModel.topPrice;
            megStr = [NSString stringWithFormat:@"复诊人数:%ld",current];
            
        }
        

    }
 
    //nslog(@"wwww%@",megStr);
    NSString *direction = @"";
    
    if (tap.view.x == 0) {
        
        direction = @"left";
    }
    
    else
    {
        direction = @"right";
    }
    
    
    [self.clinicDele showClinicMessage:megStr andIndex:self.index andDirection:direction andColorName:colorName andNowImageView:tap.view];
    
    
    
}
-(void)setDataWithArray:(NSMutableArray *)array andIndex:(NSInteger)index
{
    self.index = index;

    ZHClinicAllData *leftModel = nil;
    ZHClinicAllData *rightModel = nil;
    
   
    if (index == 0)
    {
        self.lableDate.text = @"";
        self.drawView.hidden = YES;
        self.circleLeftImage.hidden = YES;
        self.circleLeftOrangeImage.hidden = YES;
        rightModel = array[index];
        self.rightModel = rightModel;
        
        self.circleRightImage.centerY = [ZHLineGetHigh getHightWithModel:rightModel andIndex:0];
        self.circleRightOrangeImage.centerY = [ZHLineGetHigh getHightWithModel:rightModel andIndex:1];
        
        return;
        
    }
    
    else if (index == array.count)
    {
        
        self.drawView.hidden = YES;
        leftModel = array[index-1];
        self.leftModel = leftModel;
        self.circleRightImage.hidden = YES;
        self.circleRightOrangeImage.hidden = YES;
        self.circleLeftImage.centerY = [ZHLineGetHigh getHightWithModel:leftModel andIndex:0];
        self.circleLeftOrangeImage.centerY = [ZHLineGetHigh getHightWithModel:leftModel andIndex:1];
        self.lableDate.text = [NSString stringWithFormat:@"%@",[DataTool removeDateYear:leftModel.dateTime]];
        return;
       
    }
        
    self.drawView.hidden = NO;
    self.circleLeftImage.hidden = NO;
    self.circleRightImage.hidden = NO;
    
    self.circleLeftOrangeImage.hidden = NO;
    self.circleRightOrangeImage.hidden = NO;
    
    leftModel = array [index - 1];
    rightModel = array[index];
    
    self.leftModel = leftModel;
    self.rightModel = rightModel;
    
    self.circleLeftImage.centerY = [ZHLineGetHigh getHightWithModel:leftModel andIndex:0];
    self.circleRightImage.centerY = [ZHLineGetHigh getHightWithModel:rightModel andIndex:0];
    
    
    self.circleLeftOrangeImage.centerY = [ZHLineGetHigh getHightWithModel:leftModel andIndex:1];
    self.circleRightOrangeImage.centerY = [ZHLineGetHigh getHightWithModel:rightModel andIndex:1];
    
   [self.drawView setDataWithArray:array andIndex:index - 1];

    
    ZHClinicAllData *model = array[index -1];
    
    self.lableDate.text = [NSString stringWithFormat:@"%@",[DataTool removeDateYear:model.dateTime]];
   
    
}


 

@end
